package com.ruoyi.project.dict.cizu.service.impl;

import com.ruoyi.common.constant.RedisKey;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.dict.cizu.domain.CizuDetail;
import com.ruoyi.project.dict.cizu.mapper.CizuDetailMapper;
import com.ruoyi.project.dict.cizu.service.ICizuDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 词组详情Service业务层处理
 *
 * @author shixiangwen
 * @date 2020-01-15
 */
@Service
@DataSource(DataSourceType.DICT)
public class CizuDetailServiceImpl implements ICizuDetailService {

    @Autowired
    private CizuDetailMapper cizuDetailMapper;

    @Autowired
    RedisTemplate<String, String> redisTemplate;

    /**
     * 查询词组详情
     *
     * @param w 词组详情ID
     * @return 词组详情
     */
    @Override
    public CizuDetail selectCizuDetailById(String w) {
        return cizuDetailMapper.selectCizuDetailById(w);
    }

    /**
     * 查询词组详情列表
     *
     * @param cizuDetail 词组详情
     * @return 词组详情
     */
    @Override
    public List<CizuDetail> selectCizuDetailList(CizuDetail cizuDetail) {
        return cizuDetailMapper.selectCizuDetailList(cizuDetail);
    }

    /**
     * 新增词组详情
     *
     * @param cizuDetail 词组详情
     * @return 结果
     */
    @Override
    public int insertCizuDetail(CizuDetail cizuDetail) {
        return cizuDetailMapper.insertCizuDetail(cizuDetail);
    }

    /**
     * 修改词组详情
     *
     * @param cizuDetail 词组详情
     * @return 结果
     */
    @Override
    public int updateCizuDetail(CizuDetail cizuDetail) {
        int ret = cizuDetailMapper.updateCizuDetail(cizuDetail);
        redisTemplate.opsForHash().delete(RedisKey.Dict.CizuDetailKey(), cizuDetail.getW());
        return ret;
    }

    /**
     * 删除词组详情对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCizuDetailByIds(String ids) {
        return cizuDetailMapper.deleteCizuDetailByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除词组详情信息
     *
     * @param w 词组详情ID
     * @return 结果
     */
    @Override
    public int deleteCizuDetailById(String w) {
        return cizuDetailMapper.deleteCizuDetailById(w);
    }
}
